<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入easyui 的主题样式  和  easyui 提供的图标样式 -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css"  charset=UTF-8/>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css"  charset=UTF-8/>
<!-- 引入jquery 和  easyui.js   中文设置js-->
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js" charset=UTF-8></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js" charset=UTF-8></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js" charset=UTF-8></script>
</head>
<script type="text/javascript">
$(function(){
	$('#cc').combobox({    
	    url:'findkc',    
	    valueField:'id',    
	    textField:'text'   
	});  
	$('#bn1').linkbutton({ 
		onClick:function(){
			$("#kcm").text($('#cc').combobox('getText')+'成绩');
		    $('#dg').datagrid({ 
						    url:"findscore",
						    queryParams: {
						              cname: $('#cc').combobox('getText')
								},
						    columns:[[    
								{field : 'ck',width : 100,checkbox : true},
								{field:'sid',title:'学号',width:300,align:'center'},   
						        {field:'sname',title:'姓名',width:300,align:'center'},    
						        {field:'score',title:'成绩（降序）满分100',width:300,align:'center'},    						        

						    ]],  
		       pagination : true,
			   rownumbers : true,
			   pageNumber : 1,
			   pageSize : 5,
			   pageList : [ 3, 4, 5, 6, 7 ],
		       toolbar :[
		                 {iconCls : 'icon-edit',
					      text : '成绩修改申请',
					      handler : function(){ 
					    	  var stus = $('#dg').datagrid('getSelections');
								if (stus.length == 1) {
									 $("#log").dialog('open').dialog('setTitle',$("#kcm").text()+'修改');
									$("#sname").val(stus[0].sname);
									$("#score").val(stus[0].score);
									$("#sid").val(stus[0].sid);
									$("#cname").val($('#cc').combobox('getText'));
									var oldscore = $("#score").val();
									$("#btn1").linkbutton({
										onClick:function(){
											var sid = $("#sid").val();
											var cname = $('#cc').combobox('getText')
											console.log(cname);
											var newscore = $("#score").val();
											$.ajax({
												url:'updescore',
												type:'post',
												data:{'sid':sid,'cname':cname,'newscore':newscore,'oldscore':oldscore},
												datatype:'text',
												success:function(data){
													if(data=="1"){
														$.messager.alert('success','提交申请成功！','info');
														$("#log").dialog("close");
														$('#dg').datagrid('uncheckAll');
													}else{
														$.messager.alert('error','提交申请失败！','info');
														$("#log").dialog("close");
														$('#dg').datagrid('uncheckAll');
													}
												}
											})
										}

									});
									$("#btn2").linkbutton({
										onClick : function() {
											
											$("#log").dialog('close');
											$('#dg').datagrid('uncheckAll');
										}
									});
									
									

										
									} else {
									$.messager.confirm('信息', '只能选择一个', function(r) {
										if (r) {
											$('#dg').datagrid('uncheckAll');
										}
									});

								}

							
					      }} , '-',{
					    	  iconCls : 'icon-add',
						      text : '成绩录入',
						      handler : function(){
						    	  $("#log").dialog('open').dialog('setTitle',$("#kcm").text()+'录入');
						    	  $("#sname").val("");
								  $("#score").val("");
								  $("#sid").val("");
								  $("#cname").val($('#cc').combobox('getText'));
								  $("#myfrom").form({
										url : 'addscore',
										success : function(data) {
											if(data==2){	
												 $.messager.show({
										    			title:'信息提示',
										    			msg:'录入成功',
										    			timeout:1000,
										    			showType:'slide'
										    		});
												 $('#dg').datagrid('reload');
												
											}else{ $.messager.confirm({
								    			title:'信息提示',
								    			msg:'录入失败，原因：该课程没有该学生 或 该学生成绩已录入',
								    			timeout:1000,
								    			showType:'slide'
								    		}); }
										}
									})
									$("#btn1").linkbutton({
										onClick : function() {
											if(0<=$("#score").val()&$("#score").val()<=100){
												$("#myfrom").submit();
												
												}else{
													 $.messager.confirm({
											    			title:'信息提示',
											    			msg:'分数为0~100,请重新录入',
											    			timeout:1000,
											    			showType:'slide'
											    		});
												}
											
										}
									});
									$("#btn2").linkbutton({
										onClick : function() {
											
											$("#log").dialog('close');
											
										}
									});
									
						      }
					      } , '-',{
								iconCls:'icon-search',
								text:'平均分',
								handler:function(){
									$("#lg").dialog('open').dialog('setTitle',$('#cc').combobox('getText')+'平均分');
									$.ajax({
										  
										   type:'post',
										   url:'avgscore',
										   data:{'cname1':$('#cc').combobox('getText')},
										   dataType:"json",
										   success:function(e){
											   if(e){
												   var ss=e.avg
												   $("#avg1").text(ss+"分");
											   }  
			                          }
									})
									$("#btnq").linkbutton({
										onClick: function(){$("#lg").dialog('close');}
									});													
								}
							}, '-',{
								iconCls:'icon-search',
								text:'合格率',
								handler:function(){
									 $.ajax({
										   type:'post',
										   url:'passcore',
										   data:{'cnamec':$('#cc').combobox('getText')},
										   dataType:"json",
										   success:function(e){
											   
											   if(e){
												   var kk=e.passscore;
												   $("#lgj").dialog('open').dialog('setTitle',$('#cc').combobox('getText')+'及格率');
												  
					                               $("#pass1").text(kk);
											   }
											   
											   
										   }
									})
									$("#btnqj").linkbutton({
										onClick: function(){$("#lgj").dialog('close');}
									});
										 
								}
							}, '-',{iconCls:'icon-search',
								text:'查找学生成绩',
								handler:function(){
									$("#cjzs").text("");
									$('#cjczp').textbox('setText',"")
									$("#cjcz").dialog('open').dialog('setTitle',$('#cc').combobox('getText')+'成绩');
									$("#btncx").linkbutton({
									onClick:function(){ $.ajax({
										 
										   type:'post',
										   url:'cjczh',
										   data:{'snamec':$('#cjczp').textbox('getText'),'cname':$('#cc').combobox('getText')},
										   dataType:"json",
										   success:function(e){
											   
											   if(e.cj==undefined){
												   $("#cjzs").text("未找到该学生成绩");
												 
											   }else{
												   var jj=e.cj;
												   $("#cjzs").text("成绩:"+jj+"分");
											   }
											   
											   
										   }
									})}
									})
									$("#btngb").linkbutton({
										onClick:function(){
											$("#cjcz").dialog('close');
										}
									})

								}
							}
		                 ]   
				   
			});

		}   
	}); 
	
	
})

</script>

<body>
       	<!-- 课程选择下拉表 -->
<div style="margin-left: 300px;margin-top: 30px">
选择课程查询学生成绩：<input id="cc" name="dept" value="请选择课程"> 
<a id="bn1" class="easyui-linkbutton">确认</a> 
</div>
		<!-- 成绩展示表 -->	
<div style="margin-top: 20px">
<p id="kcm" style="margin-left: 430px;"></p>
<table id="dg" ></table>
</div>

        <!-- 成绩修改框与成绩录入框 -->
<div id="log" class="easyui-dialog" closed="true" buttons="#hahah" style="width:300px;height:180px;">
         <div style=" margin-left: 30px;margin-top: 20px">
		<form id="myfrom" method="post">
                        学号：<input id="sid" name="sid" type="text" >
            <br> <br>

			
			成绩：<input id="score" name="score"   > 
			
        </form>
        </div>
        
        <div id="hahah">
            <a id="btn1" class="easyui-linkbutton" iconCls ="icon-save">确认</a> 
            <a id="btn2" class="easyui-linkbutton">取消</a>

            </div>

	</div>

	

	   <!-- 平均分 -->
<div id="lg" class="easyui-dialog" closed="true" style="width:200px;height:180px;" buttons="#hahaha" >
<div style="margin-top: 60px;margin-left: 60px; " >
<span id="avg1" type="text" style="color: #0000FF"></span>
</div >
<div id="hahaha" >
 <a id="btnq" class="easyui-linkbutton">取消</a>
 </div>

</div>



       <!-- 合格率 -->
<div id="lgj" class="easyui-dialog" closed="true" style="width:200px;height:180px;" buttons="#hahahah">
<div style="margin-top: 60px;margin-left: 60px; ">
<span id="pass1" type="text" style="color: #0000FF" ></span>
</div>
<div  id="hahahah">
 <a id="btnqj" class="easyui-linkbutton">取消</a>
 </div>
</div>
       <!-- 成绩搜索-->
<div id="cjcz" class="easyui-dialog" closed="true" style="width:350px;height:200px;" >
<div style="margin-left:60px;margin-top: 30px ">
<span id="cjzs"></span>
<br><br>
<input id="cjczp" type="text"  class="easyui-textbox" data-options="iconCls:'icon-search'" prompt="输入学号或者姓名查找" style="width:150px;">
<a id="btncx" class="easyui-linkbutton">确定</a>
<a id="btngb" class="easyui-linkbutton">关闭</a>
</div>
</div>
</body>
</html>